import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout/index.vue'

export const myRoutes = [
    {
        path: '/',
        component: Layout,
        redirect: '/index',
        children: [
            {
                path: 'index',
                component: () => import('@/views/index'),
                name: 'Index',
                meta: { title: '首页', icon: 'dashboard', affix: true }
            }
        ]
    },
    {
      path: '/user',
      component: Layout,
      hidden: true,
      redirect: 'noredirect',
      children: [
        {
          path: 'profile',
          component: () => import('@/views/index'),
          name: 'Profile',
          meta: { title: '个人中心', icon: 'user' }
        }
      ]
    },
    {
      path: '/system/user-auth',
      component: Layout,
      hidden: true,
      children: [
        {
          path: 'role/:userId(\\d+)',
          component: () => import('@/views/index'),
          name: 'AuthRole',
          meta: { title: '分配角色', activeMenu: '/system/user' }
        }
      ]
    },
    {
      path: '/system/role-auth',
      component: Layout,
      hidden: true,
      children: [
        {
          path: 'user/:roleId(\\d+)',
          component: () => import('@/views/index'),
          name: 'AuthUser',
          meta: { title: '分配用户', activeMenu: '/system/role' }
        }
      ]
    },
    {
      path: '/system/dict-data',
      component: Layout,
      hidden: true,
      children: [
        {
          path: 'index/:dictId(\\d+)',
          component: () => import('@/views/index'),
          name: 'Data',
          meta: { title: '字典数据', activeMenu: '/system/dict' }
        }
      ]
    },
    {
      path: '/monitor/job-log',
      component: Layout,
      hidden: true,
      children: [
        {
          path: 'index',
          component: () => import('@/views/index'),
          name: 'JobLog',
          meta: { title: '调度日志', activeMenu: '/monitor/job' }
        }
      ]
    },
    {
      path: '/tool/gen-edit',
      component: Layout,
      hidden: true,
      children: [
        {
          path: 'index',
          component: () => import('@/views/index'),
          name: 'GenEdit',
          meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
        }
      ]
    },
    {
      path: '/iot',
      component: Layout,
      hidden: true,
      children: [
        {
          path: 'product-edit',
          component: () => import('@/views/index'),
          name: 'ProductEdit',
          meta: { title: '编辑产品', activeMenu: '/iot/product',nocache: true}
        },
        {
          path: 'device-edit',
          component: () => import('@/views/index'),
          name: 'DeviceEdit',
          meta: { title: '编辑设备', activeMenu: '/iot/device', noCache: true}
        },
      ]
    }
];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes: myRoutes,
    scrollBehavior(to, from, savedPosition) {//设置返回时回到页面指定位置
        if(savedPosition) {
            return savedPosition;
        } else {
            return {
                top: 0,
                left: 0
            }
        }
    }
});

export default router;